# -*- coding: utf-8 -*-

import platform

"""
Fingerprints the following Operating Systems:

* Mac OS X
* Ubuntu
* Red Hat
* CentOS
* FreeBSD
* SunOS
"""


class OpSysType:
    """Determins OS Type using platform module"""
    
    def __getattr__(self, attr):
        if attr == "osx":
            return "osx"
        elif attr == "rhel":
            return "RedHat"
        elif attr == "centos":
            return "CentOS"
        elif attr == "ubu":
            return "ubuntu"
        elif attr == "fbsd":
            return "FreeBSD"
        elif attr == "sun":
            return "SunOS"
        elif attr == "unknown_linux":
            return "unknown_linux"
        elif attr == "unknown":
            return "unknown"
        else:
            raise AttributeError(attr)
    
    def linux_type(self):
        """Uses various methods to determine Linux Type"""
        dist0 = platform.dist()[0]
        if dist0 == self.rhel:
            return self.rhel
        elif dist0 == self.centos:
            return self.centos
        elif dist0 == self.ubu:
            return self.ubu
        else:
            return self.unknown_linux
        
    def query_os(self):
        if platform.system() == "Darwin":
            return self.osx
        elif platform.system() == "Linux":
            return self.linux_type()
        elif platform.system() == self.sun:
            return self.sun
        elif platform.system() == self.fbsd:
            return self.fbsd


def fingerprint():
    os_type = OpSysType()
    # print(os_type.centos)
    return os_type.query_os()


if __name__ == "__main__":
    myos = fingerprint()
    print(myos)
